package everydayGrade.t3;

/**
 * @Author: Siantar
 * @Date: 2023-08-18-21:15
 * @Description: 1.0
 */
public class T1388 {
    public int maxSizeSlices(int[] slices) {
        int n = slices.length / 3;
        return Math.max(dp(slices, n, 0, slices.length - 1), dp(slices, n, 1, slices.length));
    }

    public int dp(int[] slices, int n, int left, int right) {
        int[][] f = new int[right + 1][n + 1];
        for (int i = left + 1; i <= right; ++i) {
            for (int j = 1; j <= n; ++j) {
                f[i][j] = Math.max(f[i - 1][j], (i >= 2 ? f[i - 2][j - 1] : 0) + slices[i - 1]);
            }
        }
        return f[right][n];
    }
}
